using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TemplateWeb.Controllers
{
	#region using
	using System;
	using System.Web.Mvc;
	using System.Web.Security;
	using System.Collections.Generic;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models.Repositories;
	using TemplateWeb.Helpers;
	using TemplateWeb.Models;
	using System.IO;
	#endregion
	public abstract class BaseController : Controller
	{
		protected QuanHuyenRepository _repQuanHuyen = new QuanHuyenRepository();
		protected ThongTinCongTyRepository _repThongTinCongTy = new ThongTinCongTyRepository();
		protected LoaiCamNangRepository _repLoaiCamNang = new LoaiCamNangRepository();
		protected LoaiTinTucRepository _repLoaiTinTuc = new LoaiTinTucRepository();
		protected TienIchRepository _repTienIch = new TienIchRepository();
		protected TienIchKhacRepository _repTienIchKhac = new TienIchKhacRepository();
		protected VanHoaXaHoiRepository _repVanHoaXaHoi = new VanHoaXaHoiRepository();
		protected NhaDatRepository _repNhaDat = new NhaDatRepository();
		protected CamNangRepository _repCamNang = new CamNangRepository();
		protected TinTucRepository _repTinTuc = new TinTucRepository();
		protected LoaiGiaRepository _repLoaiGia = new LoaiGiaRepository();
		protected LoaiBatDongSanRepository _repLoaiBatDongSan = new LoaiBatDongSanRepository();
		protected TinhThanhRepository _repTinhThanh = new TinhThanhRepository();
		protected NguoiDungRepository _repNguoiDung = new NguoiDungRepository();
        protected LienKetRepository _repLienKet = new LienKetRepository();
        protected HopThuRepository _repHopThu = new HopThuRepository();
        protected PhanHoiRepository _repPhanHoi = new PhanHoiRepository();
        protected ThongTinCanHoLeRepository _repThongTinCanHoLe = new ThongTinCanHoLeRepository();

		protected string RenderPartialViewToString()
		{
			return RenderPartialViewToString(null, null);
		}

		protected string RenderPartialViewToString(string viewName)
		{
			return RenderPartialViewToString(viewName, null);
		}

		protected string RenderPartialViewToString(string viewName, object model)
		{
			if (string.IsNullOrEmpty(viewName))
				viewName = ControllerContext.RouteData.GetRequiredString("action");
			ViewData.Model = model;
			using (StringWriter sw = new StringWriter())
			{
				ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
				ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
				viewResult.View.Render(viewContext, sw);
				return sw.GetStringBuilder().ToString();
			}
		}


		public GroupViewModel CreateViewModel(DataTransferViewModel dataTransfer)
		{
			GroupViewModel viewModel = new GroupViewModel();
			if (dataTransfer.EnumViewModelType.ToString().Contains("ADMIN"))
			{
                viewModel.TinhThanhModel = RetrieveTinhThanhViewModel(dataTransfer);
                viewModel.LoaiBatDongSanModel = RetrieveLoaiBatDongSanViewModel(dataTransfer);
                viewModel.LoaiTinTucModel = RetrieveLoaiTinTucViewModel(dataTransfer);
                viewModel.LoaiCamNangModel = RetrieveLoaiCamNangViewModel(dataTransfer);
			}
            if (dataTransfer.EnumViewModelType.ToString().Contains("HOME"))
            {
                viewModel.LoaiTinTucModel = RetrieveLoaiTinTucViewModel(dataTransfer);
                viewModel.LoaiBatDongSanModel = RetrieveLoaiBatDongSanViewModel(dataTransfer);
                viewModel.LoaiCamNangModel = RetrieveLoaiCamNangViewModel(dataTransfer);
                viewModel.ThongTinCongTyModel = RetrieveThongTinCongTyViewModel(dataTransfer);
                viewModel.TinTucNewestModel = RetrieveNewTinTucViewModel(dataTransfer);
                viewModel.CamNangNewestModel = RetrieveNewCamNangViewModel(dataTransfer);
                viewModel.LienKetModel = RetrieveLienKetViewModel(dataTransfer);
            }
			switch (dataTransfer.EnumViewModelType)
			{
				case EnumViewModel.ADMIN_DETAILOF_THONGTINCONGTY:
                    viewModel.ThongTinCongTyModel = RetrieveDetailOfThongTinCongTyViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_DETAILOF_NGUOIDUNG:
					break;
				case EnumViewModel.ADMIN_DETAILOF_NHADAT:
                    viewModel.NhaDatModel = RetrieveDetailOfNhaDatViewModel(dataTransfer);
                    viewModel.LoaiGiaModel = RetrieveLoaiGiaViewModel(dataTransfer);
                    if (viewModel.NhaDatModel.GetModel.LstObjModel[0].LoaiBatDongSan.TenLoaiBatDongSan.ToUpper().Contains(WebConfiguration.NhaDatLe))
                    {
                        if (viewModel.NhaDatModel.GetModel.LstObjModel[0].LoaiBatDongSan.TenLoaiBatDongSan.ToUpper().Contains(WebConfiguration.CanHo))
                        {
                            if (viewModel.NhaDatModel.GetModel.LstObjModel[0].TienIch == null)
                                viewModel.NhaDatModel.GetModel.LstObjModel[0].TienIch = RetrieveTienIchNhaDatViewModel(dataTransfer).GetModel.LstObjModel[0];
                            if (viewModel.NhaDatModel.GetModel.LstObjModel[0].TienIchKhac == null)
                                viewModel.NhaDatModel.GetModel.LstObjModel[0].TienIchKhac = RetrieveTienIchKhacViewModel(dataTransfer).GetModel.LstObjModel[0];
                            if (viewModel.NhaDatModel.GetModel.LstObjModel[0].ThongTinCanHoLe == null)
                                viewModel.NhaDatModel.GetModel.LstObjModel[0].ThongTinCanHoLe = RetrieveThongTinCanHoLeNhaDatViewModel(dataTransfer).GetModel.LstObjModel[0];
                        }
                        if (viewModel.NhaDatModel.GetModel.LstObjModel[0].VanHoaXaHoi == null)
                            viewModel.NhaDatModel.GetModel.LstObjModel[0].VanHoaXaHoi = RetrieveVanHoaXaHoiKhacNhaDatViewModel(dataTransfer).GetModel.LstObjModel[0];
                    }
					break;
				case EnumViewModel.ADMIN_DETAILOF_CAMNANG:
                    viewModel.CamNangModel = RetrieveDetailOfCamNangViewModel(dataTransfer);
					break;
                case EnumViewModel.ADMIN_DETAILOF_PHANHOI:
                    viewModel.PhanHoiModel = RetriveDetailOfPhanHoiViewModel(dataTransfer);
                    break;
				case EnumViewModel.ADMIN_DETAILOF_TINTUC:
                    viewModel.TinTucModel = RetrieveDetailOfTinTucViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_QUANHUYEN:
                    viewModel.QuanHuyenModel = RetrieveQuanHuyenViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_THONGTINCONGTY:
                    viewModel.ThongTinCongTyModel = RetrieveThongTinCongTyViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_NGUOIDUNG:
                    viewModel.NguoiDungModel = RetrieveNguoiDungViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_LOAICAMNANG:
					break;
				case EnumViewModel.ADMIN_LOAITINTUC:
					break;
				case EnumViewModel.ADMIN_CANHO:
					break;
				case EnumViewModel.ADMIN_TIENICH:
					break;
				case EnumViewModel.ADMIN_TIENICHKHAC:
					break;
				case EnumViewModel.ADMIN_VANHOAXAHOI:
					break;
				case EnumViewModel.ADMIN_NHADAT:
                    viewModel.NhaDatModel = RetrieveNhaDatViewModel(dataTransfer);
                    viewModel.LoaiGiaModel = RetrieveLoaiGiaViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_CAMNANG:
                    viewModel.CamNangModel = RetrieveCamNangViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_TINTUC:
                    viewModel.TinTucModel = RetrieveTinTucViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_LOAIGIA:
                    viewModel.LoaiGiaModel = RetrieveLoaiGiaViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_LOAIBATDONGSAN:
					break;
				case EnumViewModel.ADMIN_TINHTHANH:
					break;
                case EnumViewModel.ADMIN_LIENKET:
                    viewModel.LienKetModel = RetrieveLienKetViewModel(dataTransfer);
                    break;
                case EnumViewModel.ADMIN_HOPTHU:
                    viewModel.HopThuModel = RetrieveHopThuViewModel(dataTransfer);
                    break;
                case EnumViewModel.ADMIN_PHANHOI:
                    viewModel.PhanHoiModel = RetrievePhanHoiViewModel(dataTransfer);
                    dataTransfer.EditID = dataTransfer.IDHopThu;
                    viewModel.HopThuModel = RetriveDetailOfHopThuViewModel(dataTransfer);
                    break;
				case EnumViewModel.HOME_REGISTER:
					break;
                case EnumViewModel.HOME_INDEX:
                    viewModel.DuAnVipModel = RetrieveDuAnVipViewModel(dataTransfer);
                    viewModel.DuAnTieuBieuModel = RetrieveDuAnTieuBieuViewModel(dataTransfer);
                    viewModel.DuAnNewestModel = RetrieveDuAnNewestViewModel(dataTransfer);
                    viewModel.SanPhamLeTieuBieuModel = RetrieveSanPhamLeTieuBieuViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_TINTUC:
                    viewModel.TinTucModel = RetrieveTinTucViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_CAMNANG:
                    viewModel.CamNangModel = RetrieveCamNangViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_DETAILOF_TINTUC:
                    viewModel.TinTucModel = RetrieveDetailOfTinTucViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_DETAILOF_CAMNANG:
                    viewModel.CamNangModel = RetrieveDetailOfCamNangViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_NHADAT:
                    viewModel.NhaDatModel = RetrieveNhaDatViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_NHADAT_DATNEN:
                    viewModel.NhaDatModel = RetrieveDatNenViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_NHADAT_CANHO:
                    viewModel.NhaDatModel = RetrieveCanHoViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_GIOITHIEU:
                    viewModel.ThongTinCongTyModel = RetrieveThongTinCongTyViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_HOPTHU:
                    viewModel.ThongTinCongTyModel = RetrieveThongTinCongTyViewModel(dataTransfer);
                    viewModel.HopThuModel = RetrieveKetQuaLienHeViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_DETAILOF_NHADAT:
                    viewModel.NhaDatModel = RetrieveDetailOfNhaDatViewModel(dataTransfer);
                    if (viewModel.NhaDatModel.GetModel.LstObjModel[0].LoaiBatDongSan.TenLoaiBatDongSan.ToUpper().Contains(WebConfiguration.NhaDatLe))
                    {
                        if (viewModel.NhaDatModel.GetModel.LstObjModel[0].LoaiBatDongSan.TenLoaiBatDongSan.ToUpper().Contains(WebConfiguration.CanHo))
                        {
                            if (viewModel.NhaDatModel.GetModel.LstObjModel[0].TienIch == null)
                                viewModel.NhaDatModel.GetModel.LstObjModel[0].TienIch = RetrieveTienIchNhaDatViewModel(dataTransfer).GetModel.LstObjModel[0];
                            if (viewModel.NhaDatModel.GetModel.LstObjModel[0].TienIchKhac == null)
                                viewModel.NhaDatModel.GetModel.LstObjModel[0].TienIchKhac = RetrieveTienIchKhacViewModel(dataTransfer).GetModel.LstObjModel[0];
                            if (viewModel.NhaDatModel.GetModel.LstObjModel[0].ThongTinCanHoLe == null)
                                viewModel.NhaDatModel.GetModel.LstObjModel[0].ThongTinCanHoLe = RetrieveThongTinCanHoLeNhaDatViewModel(dataTransfer).GetModel.LstObjModel[0];
                        }
                        if (viewModel.NhaDatModel.GetModel.LstObjModel[0].VanHoaXaHoi == null)
                            viewModel.NhaDatModel.GetModel.LstObjModel[0].VanHoaXaHoi = RetrieveVanHoaXaHoiKhacNhaDatViewModel(dataTransfer).GetModel.LstObjModel[0];
                    }
                    break;
                case EnumViewModel.HOME_DETAILOF_NGUOIDUNG:
                    viewModel.DetaiOfNguoiDungModel = RetrieveDetailOfNguoiDungViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_DANGTIN:
                    viewModel.TinhThanhModel = RetrieveTinhThanhViewModel(dataTransfer);
                    viewModel.QuanHuyenModel = RetrieveQuanHuyenDangTinViewModel(dataTransfer);
                    viewModel.LoaiGiaModel = RetrieveLoaiGiaViewModel(dataTransfer);
                    viewModel.NguoiDungModel = RetrieveDetailOfNguoiDungViewModel(dataTransfer);
                    viewModel.LoaiBatDongSanModel = RetrieveLoaiBatDongSanViewModel(dataTransfer);
                    break;
			}
			return viewModel;
		}

        public bool SendingMail(string subject, string emailContent, string to)
        {
            bool result = false;
            try
            {
                System.Net.Mail.SmtpClient mailclient = new System.Net.Mail.SmtpClient();
                System.Net.NetworkCredential auth = new System.Net.NetworkCredential(WebConfiguration.EmailLienHe, WebConfiguration.PasswordEmailLienHe);
                mailclient.Host = WebConfiguration.MailServer;
                mailclient.EnableSsl = true;
                mailclient.UseDefaultCredentials = true;
                mailclient.Credentials = auth;

                System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(WebConfiguration.EmailLienHe, to);
                mm.Subject = subject;
                mm.IsBodyHtml = true;
                mm.Body = emailContent;

                mailclient.Send(mm);
                result = true;
            }
            catch
            {
                result = false;
            }

            return result;
        }

		public bool UploadFile(HttpPostedFileBase file, string path, string name, ref string refName)
		{
			try
			{
                if (!System.IO.File.Exists(Server.MapPath(path + file.FileName)))
                {
                    FileInfo f = new FileInfo(path + file.FileName);
                    long ngay = DateTime.Now.ToBinary();
                    refName = name + ngay + f.Extension;
                    string fullPath = path + refName;
                    if (file == null)
                        return false;
                    byte[] buffer = new byte[file.ContentLength];
                    file.InputStream.Read(buffer, 0, file.ContentLength);
                    FileStream newFile = new FileStream(Server.MapPath(fullPath), FileMode.Create, FileAccess.Write);
                    newFile.Write(buffer, 0, file.ContentLength);
                    newFile.Close();
                }
                else
                {
                    refName = file.FileName;
                }
                
				return true;
			}
			catch
			{
				return false;
			}
		}

		public void DeleteFile(string filePath)
		{
			FileInfo file = new FileInfo(filePath);
			if (file.Exists)
			{
				file.Delete();
			}
		}

        public HopThuViewModel RetrieveKetQuaLienHeViewModel(DataTransferViewModel dataTransfer)
        {
            return new HopThuViewModel
            {
                GetModel = new GetHopThuViewModel
                {
                },
                AddModel = new AddHopThuViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditHopThuViewModel
                {
                }
            };
        }

        public HopThuViewModel RetrieveHopThuViewModel(DataTransferViewModel dataTransfer)
        {
            List<HopThu> lst = null;
            lst = _repHopThu.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
            var totalitem = _repHopThu.GetTotalItem();

            return new HopThuViewModel
            {
                GetModel = new GetHopThuViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddHopThuViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditHopThuViewModel
                {
                    ID = dataTransfer.EditID
                }
            };
        }

        public PhanHoiViewModel RetrievePhanHoiViewModel(DataTransferViewModel dataTransfer)
        {
            List<PhanHoi> lst = null;
            int totalitem = -1;
            if (dataTransfer.IDHopThu != -1)
            {
                lst = _repPhanHoi.SelectByHopThu(dataTransfer.IDHopThu, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
                totalitem = _repPhanHoi.GetTotalItemByHopThu(dataTransfer.IDHopThu);
            }
            else
            {
                lst = _repPhanHoi.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
                totalitem = _repPhanHoi.GetTotalItem();
            }
            return new PhanHoiViewModel
            {
                GetModel = new GetPhanHoiViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddPhanHoiViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditPhanHoiViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new PhanHoiReferKeys()
                {
                    IDHopThu = dataTransfer.IDHopThu,
                    IDNguoiPhanHoi = dataTransfer.IDNguoiDang,
                }
            };
        }

        public QuanHuyenViewModel RetrieveQuanHuyenDangTinViewModel(DataTransferViewModel dataTransfer)
        {
            List<QuanHuyen> lst = null;
            int totalitem = -1;
            if (dataTransfer.IDTinhThanh != -1)
            {
                lst = _repQuanHuyen.SelectByTinhThanh(dataTransfer.IDTinhThanh, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
                totalitem = _repQuanHuyen.GetTotalItemByTinhThanh(dataTransfer.IDTinhThanh);
            }
            else
            {
                lst = new List<QuanHuyen>();
                totalitem = 0;
            }
            return new QuanHuyenViewModel
            {
                GetModel = new GetQuanHuyenViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddQuanHuyenViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditQuanHuyenViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new QuanHuyenReferKeys()
                {
                    IDTinhThanh = dataTransfer.IDTinhThanh,
                }
            };
        }

		public QuanHuyenViewModel RetrieveQuanHuyenViewModel(DataTransferViewModel dataTransfer)
		{
			List<QuanHuyen> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDTinhThanh != -1)
			{
				lst = _repQuanHuyen.SelectByTinhThanh(dataTransfer.IDTinhThanh, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repQuanHuyen.GetTotalItemByTinhThanh(dataTransfer.IDTinhThanh);
			}
			else
			{
				lst = _repQuanHuyen.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repQuanHuyen.GetTotalItem();
			}
			return new QuanHuyenViewModel
			{
				GetModel = new GetQuanHuyenViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddQuanHuyenViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditQuanHuyenViewModel
				{
					ID = dataTransfer.EditID
				},
				ReferKeys = new QuanHuyenReferKeys()
				{
					IDTinhThanh = dataTransfer.IDTinhThanh,
				}
			};
		}

        public LienKetViewModel RetrieveLienKetViewModel(DataTransferViewModel dataTransfer)
        {
            return new LienKetViewModel
            {
                GetModel = new GetLienKetViewModel
                {
                    LstObjModel = _repLienKet.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage),
                    TotalItem = _repLienKet.GetTotalItem(),
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddLienKetViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditLienKetViewModel
                {
                    ID = dataTransfer.EditID,
                    Edited = dataTransfer.Updated
                }
            };
        }

		public ThongTinCongTyViewModel RetrieveThongTinCongTyViewModel(DataTransferViewModel dataTransfer)
		{
			return new ThongTinCongTyViewModel
			{
				GetModel = new GetThongTinCongTyViewModel
				{
					LstObjModel = _repThongTinCongTy.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage),
					TotalItem = _repThongTinCongTy.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddThongTinCongTyViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditThongTinCongTyViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}

		public LoaiCamNangViewModel RetrieveLoaiCamNangViewModel(DataTransferViewModel dataTransfer)
		{
			return new LoaiCamNangViewModel
			{
				GetModel = new GetLoaiCamNangViewModel
				{
					LstObjModel = _repLoaiCamNang.SelectAll(),
					TotalItem = _repLoaiCamNang.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddLoaiCamNangViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditLoaiCamNangViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}

		public LoaiTinTucViewModel RetrieveLoaiTinTucViewModel(DataTransferViewModel dataTransfer)
		{
			return new LoaiTinTucViewModel
			{
				GetModel = new GetLoaiTinTucViewModel
				{
					LstObjModel = _repLoaiTinTuc.SelectAll(),
					TotalItem = _repLoaiTinTuc.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddLoaiTinTucViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditLoaiTinTucViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}

		public TienIchViewModel RetrieveTienIchViewModel(DataTransferViewModel dataTransfer)
		{
			List<TienIch> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDNhaDat != -1)
			{
				lst = _repTienIch.SelectByNhaDat(dataTransfer.IDNhaDat, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repTienIch.GetTotalItemByNhaDat(dataTransfer.IDNhaDat);
			}
			else
			{
				lst = _repTienIch.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repTienIch.GetTotalItem();
			}
			return new TienIchViewModel
			{
				GetModel = new GetTienIchViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddTienIchViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditTienIchViewModel
				{
					ID = dataTransfer.EditID
				},
				ReferKeys = new TienIchReferKeys()
				{
					IDNhaDat = dataTransfer.IDNhaDat,
				}
			};
		}

		public TienIchKhacViewModel RetrieveTienIchKhacViewModel(DataTransferViewModel dataTransfer)
		{
			List<TienIchKhac> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDNhaDat != -1)
			{
				lst = _repTienIchKhac.SelectByNhaDat(dataTransfer.IDNhaDat, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repTienIchKhac.GetTotalItemByNhaDat(dataTransfer.IDNhaDat);
			}
			else
			{
				lst = _repTienIchKhac.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repTienIchKhac.GetTotalItem();
			}
			return new TienIchKhacViewModel
			{
				GetModel = new GetTienIchKhacViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddTienIchKhacViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditTienIchKhacViewModel
				{
					ID = dataTransfer.EditID
				},
				ReferKeys = new TienIchKhacReferKeys()
				{
					IDNhaDat = dataTransfer.IDNhaDat,
				}
			};
		}

		public VanHoaXaHoiViewModel RetrieveVanHoaXaHoiViewModel(DataTransferViewModel dataTransfer)
		{
			List<VanHoaXaHoi> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDNhaDat != -1)
			{
				lst = _repVanHoaXaHoi.SelectByNhaDat(dataTransfer.IDNhaDat, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repVanHoaXaHoi.GetTotalItemByNhaDat(dataTransfer.IDNhaDat);
			}
			else
			{
				lst = _repVanHoaXaHoi.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repVanHoaXaHoi.GetTotalItem();
			}
			return new VanHoaXaHoiViewModel
			{
				GetModel = new GetVanHoaXaHoiViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddVanHoaXaHoiViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditVanHoaXaHoiViewModel
				{
					ID = dataTransfer.EditID
				},
				ReferKeys = new VanHoaXaHoiReferKeys()
				{
					IDNhaDat = dataTransfer.IDNhaDat,
				}
			};
		}

        public NhaDatViewModel RetrieveDuAnVipViewModel(DataTransferViewModel dataTransfer)
        {
            List<NhaDat> lst = null;
            int totalitem = -1;
            lst = _repNhaDat.SelectDuAnVip(WebConfiguration.TopDuAnTieuBieuPerPage);
            totalitem = _repNhaDat.GetTotalItem();
            return new NhaDatViewModel
            {
                GetModel = new GetNhaDatViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddNhaDatViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditNhaDatViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new NhaDatReferKeys()
                {
                    IDLoaiBatDongSan = dataTransfer.IDLoaiBatDongSan,
                    IDQuanHuyen = dataTransfer.IDQuanHuyen,
                    IDLoaiGia = dataTransfer.IDLoaiGia,
                    IDNguoiDang = dataTransfer.IDNguoiDang,
                }
            };
        }

        public NhaDatViewModel RetrieveDuAnTieuBieuViewModel(DataTransferViewModel dataTransfer)
        {
            List<NhaDat> lst = null;
            int totalitem = -1;
            lst = _repNhaDat.SelectDuAnTieuBieu(WebConfiguration.TopDuAnTieuBieuPerPage);
            totalitem = _repNhaDat.GetTotalItem();
            return new NhaDatViewModel
            {
                GetModel = new GetNhaDatViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddNhaDatViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditNhaDatViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new NhaDatReferKeys()
                {
                    IDLoaiBatDongSan = dataTransfer.IDLoaiBatDongSan,
                    IDQuanHuyen = dataTransfer.IDQuanHuyen,
                    IDLoaiGia = dataTransfer.IDLoaiGia,
                    IDNguoiDang = dataTransfer.IDNguoiDang,
                }
            };
        }

        public NhaDatViewModel RetrieveDuAnNewestViewModel(DataTransferViewModel dataTransfer)
        {
            List<NhaDat> lst = null;
            int totalitem = -1;
            lst = _repNhaDat.SelectDuAnMoiNhat(WebConfiguration.SanPhamTieuBieuPerPage);
            totalitem = _repNhaDat.GetTotalItem();
            return new NhaDatViewModel
            {
                GetModel = new GetNhaDatViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddNhaDatViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditNhaDatViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new NhaDatReferKeys()
                {
                    IDLoaiBatDongSan = dataTransfer.IDLoaiBatDongSan,
                    IDQuanHuyen = dataTransfer.IDQuanHuyen,
                    IDLoaiGia = dataTransfer.IDLoaiGia,
                    IDNguoiDang = dataTransfer.IDNguoiDang,
                }
            };
        }

        public NhaDatViewModel RetrieveSanPhamLeTieuBieuViewModel(DataTransferViewModel dataTransfer)
        {
            List<NhaDat> lst = null;
            int totalitem = -1;
            lst = _repNhaDat.SelectSanPhamLeTieuBieu(WebConfiguration.SanPhamTieuBieuPerPage);
            totalitem = _repNhaDat.GetTotalItem();
            return new NhaDatViewModel
            {
                GetModel = new GetNhaDatViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddNhaDatViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditNhaDatViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new NhaDatReferKeys()
                {
                    IDLoaiBatDongSan = dataTransfer.IDLoaiBatDongSan,
                    IDQuanHuyen = dataTransfer.IDQuanHuyen,
                    IDLoaiGia = dataTransfer.IDLoaiGia,
                    IDNguoiDang = dataTransfer.IDNguoiDang,
                }
            };
        }

        public NhaDatViewModel RetrieveDatNenViewModel(DataTransferViewModel dataTransfer)
        {
            List<NhaDat> lst = null;
            int totalitem = -1;
            lst = _repNhaDat.SelectDatNen();
            totalitem = _repNhaDat.GetTotalItem();
            return new NhaDatViewModel
            {
                GetModel = new GetNhaDatViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddNhaDatViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditNhaDatViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new NhaDatReferKeys()
                {
                    IDLoaiBatDongSan = dataTransfer.IDLoaiBatDongSan,
                    IDQuanHuyen = dataTransfer.IDQuanHuyen,
                    IDLoaiGia = dataTransfer.IDLoaiGia,
                    IDNguoiDang = dataTransfer.IDNguoiDang,
                }
            };
        }

        public NhaDatViewModel RetrieveCanHoViewModel(DataTransferViewModel dataTransfer)
        {
            List<NhaDat> lst = null;
            int totalitem = -1;
            lst = _repNhaDat.SelectCanHo();
            totalitem = _repNhaDat.GetTotalItem();
            return new NhaDatViewModel
            {
                GetModel = new GetNhaDatViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddNhaDatViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditNhaDatViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new NhaDatReferKeys()
                {
                    IDLoaiBatDongSan = dataTransfer.IDLoaiBatDongSan,
                    IDQuanHuyen = dataTransfer.IDQuanHuyen,
                    IDLoaiGia = dataTransfer.IDLoaiGia,
                    IDNguoiDang = dataTransfer.IDNguoiDang,
                }
            };
        }

		public NhaDatViewModel RetrieveNhaDatViewModel(DataTransferViewModel dataTransfer)
		{
			List<NhaDat> lst = null;
			int totalitem = -1;
            if (dataTransfer.IDLoaiBatDongSan != -1 && dataTransfer.IDQuanHuyen != -1)
			{
                lst = _repNhaDat.SelectByLoaiBatDongSanQuanHuyen(dataTransfer.IDLoaiBatDongSan, dataTransfer.IDQuanHuyen, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
                totalitem = _repNhaDat.GetTotalItemByLoaiBatDongSanQuanHuyen(dataTransfer.IDLoaiBatDongSan, dataTransfer.IDQuanHuyen);
			}
			else if (dataTransfer.IDLoaiBatDongSan != -1)
			{
                lst = _repNhaDat.SelectByLoaiBatDongSan(dataTransfer.IDLoaiBatDongSan, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
                totalitem = _repNhaDat.GetTotalItemByLoaiBatDongSan(dataTransfer.IDLoaiBatDongSan);
			}
			else if (dataTransfer.IDQuanHuyen != -1)
			{
				lst = _repNhaDat.SelectByQuanHuyen(dataTransfer.IDQuanHuyen, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repNhaDat.GetTotalItemByQuanHuyen(dataTransfer.IDQuanHuyen);
			}
			else if (dataTransfer.IDLoaiGia != -1)
			{
				lst = _repNhaDat.SelectByLoaiGia(dataTransfer.IDLoaiGia, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repNhaDat.GetTotalItemByLoaiGia(dataTransfer.IDLoaiGia);
			}
			else if (dataTransfer.IDNguoiDang != Guid.Parse("11112222-1111-1111-1111-111122223333"))
			{
				lst = _repNhaDat.SelectByNguoiDang(dataTransfer.IDNguoiDang, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repNhaDat.GetTotalItemByNguoiDang(dataTransfer.IDNguoiDang);
			}
			else
			{
				lst = _repNhaDat.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repNhaDat.GetTotalItem();
			}
			return new NhaDatViewModel
			{
				GetModel = new GetNhaDatViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddNhaDatViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditNhaDatViewModel
				{
					ID = dataTransfer.EditID
				},
				ReferKeys = new NhaDatReferKeys()
				{
					IDLoaiBatDongSan = dataTransfer.IDLoaiBatDongSan,
					IDQuanHuyen = dataTransfer.IDQuanHuyen,
					IDLoaiGia = dataTransfer.IDLoaiGia,
					IDNguoiDang = dataTransfer.IDNguoiDang,
				}
			};
		}

        public CamNangViewModel RetrieveNewCamNangViewModel(DataTransferViewModel dataTransfer)
        {
            List<CamNang> lst = null;
            int totalitem = -1;
            lst = _repCamNang.SelectFirstPage(dataTransfer.ProductsPerPage);
            totalitem = _repCamNang.GetTotalItem();
            return new CamNangViewModel
            {
                GetModel = new GetCamNangViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddCamNangViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditCamNangViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new CamNangReferKeys()
                {
                    IDLoaiCamNang = dataTransfer.IDLoaiCamNang,
                    IDNguoiDang = dataTransfer.IDNguoiDang,
                }
            };
        }

		public CamNangViewModel RetrieveCamNangViewModel(DataTransferViewModel dataTransfer)
		{
			List<CamNang> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDLoaiCamNang != -1)
			{
				lst = _repCamNang.SelectByLoaiCamNang(dataTransfer.IDLoaiCamNang, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repCamNang.GetTotalItemByLoaiCamNang(dataTransfer.IDLoaiCamNang);
			}
			else if (dataTransfer.IDNguoiDang != Guid.Parse("11112222-1111-1111-1111-111122223333"))
			{
				lst = _repCamNang.SelectByNguoiDang(dataTransfer.IDNguoiDang, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repCamNang.GetTotalItemByNguoiDang(dataTransfer.IDNguoiDang);
			}
			else
			{
				lst = _repCamNang.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repCamNang.GetTotalItem();
			}
			return new CamNangViewModel
			{
				GetModel = new GetCamNangViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddCamNangViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditCamNangViewModel
				{
					ID = dataTransfer.EditID
				},
				ReferKeys = new CamNangReferKeys()
				{
					IDLoaiCamNang = dataTransfer.IDLoaiCamNang,
					IDNguoiDang = dataTransfer.IDNguoiDang,
				}
			};
		}

        public TinTucViewModel RetrieveNewTinTucViewModel(DataTransferViewModel dataTransfer)
        {
            List<TinTuc> lst = null;
            int totalitem = -1;
            lst = _repTinTuc.SelectFirstPage(dataTransfer.ProductsPerPage);
            totalitem = _repTinTuc.GetTotalItem();
            return new TinTucViewModel
            {
                GetModel = new GetTinTucViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddTinTucViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditTinTucViewModel
                {
                    ID = dataTransfer.EditID
                },
                ReferKeys = new TinTucReferKeys()
                {
                    IDLoaiTinTuc = dataTransfer.IDLoaiTinTuc,
                    IDNguoiDang = dataTransfer.IDNguoiDang,
                }
            };
        }

		public TinTucViewModel RetrieveTinTucViewModel(DataTransferViewModel dataTransfer)
		{
			List<TinTuc> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDLoaiTinTuc != -1)
			{
				lst = _repTinTuc.SelectByLoaiTinTuc(dataTransfer.IDLoaiTinTuc, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repTinTuc.GetTotalItemByLoaiTinTuc(dataTransfer.IDLoaiTinTuc);
			}
			else if (dataTransfer.IDNguoiDang != Guid.Parse("11112222-1111-1111-1111-111122223333"))
			{
				lst = _repTinTuc.SelectByNguoiDang(dataTransfer.IDNguoiDang, dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repTinTuc.GetTotalItemByNguoiDang(dataTransfer.IDNguoiDang);
			}
			else
			{
				lst = _repTinTuc.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repTinTuc.GetTotalItem();
			}
			return new TinTucViewModel
			{
				GetModel = new GetTinTucViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddTinTucViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditTinTucViewModel
				{
					ID = dataTransfer.EditID
				},
				ReferKeys = new TinTucReferKeys()
				{
					IDLoaiTinTuc = dataTransfer.IDLoaiTinTuc,
					IDNguoiDang = dataTransfer.IDNguoiDang,
				}
			};
		}

		public LoaiGiaViewModel RetrieveLoaiGiaViewModel(DataTransferViewModel dataTransfer)
		{
			return new LoaiGiaViewModel
			{
				GetModel = new GetLoaiGiaViewModel
				{
					LstObjModel = _repLoaiGia.SelectAll(),
					TotalItem = _repLoaiGia.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddLoaiGiaViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditLoaiGiaViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}

		public LoaiBatDongSanViewModel RetrieveLoaiBatDongSanViewModel(DataTransferViewModel dataTransfer)
		{
			return new LoaiBatDongSanViewModel
			{
				GetModel = new GetLoaiBatDongSanViewModel
				{
					LstObjModel = _repLoaiBatDongSan.SelectAll(),
					TotalItem = _repLoaiBatDongSan.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddLoaiBatDongSanViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditLoaiBatDongSanViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}

		public TinhThanhViewModel RetrieveTinhThanhViewModel(DataTransferViewModel dataTransfer)
		{
			return new TinhThanhViewModel
			{
				GetModel = new GetTinhThanhViewModel
				{
					LstObjModel = _repTinhThanh.SelectAll(),
					TotalItem = _repTinhThanh.GetTotalItem(),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddTinhThanhViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditTinhThanhViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}


		public NguoiDungViewModel RetrieveNguoiDungViewModel(DataTransferViewModel dataTransfer)
		{
			return new NguoiDungViewModel
			{
				GetModel = new GetNguoiDungViewModel
				{
					LstObjModel = _repNguoiDung.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage, dataTransfer.Role),
					TotalItem = _repNguoiDung.GetTotalItem(dataTransfer.Role),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddNguoiDungViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditNguoiDungViewModel
				{
					ID = dataTransfer.EditIDNguoiDung,
					Edited = dataTransfer.Updated
				}
			};
		}

		public ThongTinCongTyViewModel RetrieveDetailOfThongTinCongTyViewModel(DataTransferViewModel dataTransfer)
		{
			return new ThongTinCongTyViewModel
			{
				GetModel = new GetThongTinCongTyViewModel
				{
					LstObjModel = _repThongTinCongTy.RetrieveByID(dataTransfer.EditID)
				},
				AddModel = new AddThongTinCongTyViewModel(),
				EditModel = new EditThongTinCongTyViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}
		public NhaDatViewModel RetrieveDetailOfNhaDatViewModel(DataTransferViewModel dataTransfer)
		{
            _repNhaDat.UpdateSoLanXem(dataTransfer.EditID);
			return new NhaDatViewModel
			{
				GetModel = new GetNhaDatViewModel
				{
					LstObjModel = _repNhaDat.RetrieveByID(dataTransfer.EditID)
				},
				AddModel = new AddNhaDatViewModel(),
				EditModel = new EditNhaDatViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}

        public TienIchViewModel RetrieveTienIchNhaDatViewModel(DataTransferViewModel dataTransfer)
        {
            return new TienIchViewModel
            {
                GetModel = new GetTienIchViewModel
                {
                    LstObjModel = _repTienIch.RetrieveByID(dataTransfer.EditID)
                },
                AddModel = new AddTienIchViewModel(),
                EditModel = new EditTienIchViewModel
                {
                    ID = dataTransfer.EditID,
                    Edited = dataTransfer.Updated
                }
            };
        }

        public TienIchKhacViewModel RetrieveTienIchKhacNhaDatViewModel(DataTransferViewModel dataTransfer)
        {
            return new TienIchKhacViewModel
            {
                GetModel = new GetTienIchKhacViewModel
                {
                    LstObjModel = _repTienIchKhac.RetrieveByID(dataTransfer.EditID)
                },
                AddModel = new AddTienIchKhacViewModel(),
                EditModel = new EditTienIchKhacViewModel
                {
                    ID = dataTransfer.EditID,
                    Edited = dataTransfer.Updated
                }
            };
        }

        public VanHoaXaHoiViewModel RetrieveVanHoaXaHoiKhacNhaDatViewModel(DataTransferViewModel dataTransfer)
        {
            return new VanHoaXaHoiViewModel
            {
                GetModel = new GetVanHoaXaHoiViewModel
                {
                    LstObjModel = _repVanHoaXaHoi.RetrieveByID(dataTransfer.EditID)
                },
                AddModel = new AddVanHoaXaHoiViewModel(),
                EditModel = new EditVanHoaXaHoiViewModel
                {
                    ID = dataTransfer.EditID,
                    Edited = dataTransfer.Updated
                }
            };
        }

        public ThongTinCanHoLeViewModel RetrieveThongTinCanHoLeNhaDatViewModel(DataTransferViewModel dataTransfer)
        {
            return new ThongTinCanHoLeViewModel
            {
                GetModel = new GetThongTinCanHoLeViewModel
                {
                    LstObjModel = _repThongTinCanHoLe.RetrieveByID(dataTransfer.EditID)
                },
                AddModel = new AddThongTinCanHoLeViewModel(),
                EditModel = new EditThongTinCanHoLeViewModel
                {
                    ID = dataTransfer.EditID,
                    Edited = dataTransfer.Updated
                }
            };
        }

		public CamNangViewModel RetrieveDetailOfCamNangViewModel(DataTransferViewModel dataTransfer)
		{
			return new CamNangViewModel
			{
				GetModel = new GetCamNangViewModel
				{
					LstObjModel = _repCamNang.RetrieveByID(dataTransfer.EditID)
				},
				AddModel = new AddCamNangViewModel(),
				EditModel = new EditCamNangViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}
		public TinTucViewModel RetrieveDetailOfTinTucViewModel(DataTransferViewModel dataTransfer)
		{
			return new TinTucViewModel
			{
				GetModel = new GetTinTucViewModel
				{
					LstObjModel = _repTinTuc.RetrieveByID(dataTransfer.EditID)
				},
				AddModel = new AddTinTucViewModel(),
				EditModel = new EditTinTucViewModel
				{
					ID = dataTransfer.EditID,
					Edited = dataTransfer.Updated
				}
			};
		}

        public NguoiDungViewModel RetrieveDetailOfNguoiDungViewModel(DataTransferViewModel dataTransfer)
        {
            return new NguoiDungViewModel
            {
                GetModel = new GetNguoiDungViewModel
                {
                    LstObjModel = _repNguoiDung.RetrieveByUserName(dataTransfer.UserName)
                },
                AddModel = new AddNguoiDungViewModel
                {
                    Added = dataTransfer.Added
                },
                EditModel = new EditNguoiDungViewModel
                {
                    Edited = dataTransfer.Updated
                }
            };
        }

        public HopThuViewModel RetriveDetailOfHopThuViewModel(DataTransferViewModel dataTransfer)
        {
            return new HopThuViewModel
            {
                GetModel = new GetHopThuViewModel
                {
                    LstObjModel = _repHopThu.RetrieveByID(dataTransfer.EditID)
                },
                AddModel = new AddHopThuViewModel(),
                EditModel = new EditHopThuViewModel
                {
                    ID = dataTransfer.EditID,
                    Edited = dataTransfer.Updated
                }
            };
        }

        public PhanHoiViewModel RetriveDetailOfPhanHoiViewModel(DataTransferViewModel dataTransfer)
        {
            return new PhanHoiViewModel
            {
                GetModel = new GetPhanHoiViewModel
                {
                    LstObjModel = _repPhanHoi.RetrieveByID(dataTransfer.EditID)
                },
                AddModel = new AddPhanHoiViewModel(),
                EditModel = new EditPhanHoiViewModel
                {
                    ID = dataTransfer.EditID,
                    Edited = dataTransfer.Updated
                }
            };
        }
	}
}